package cn.stylefeng.guns.modular.controller;


import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.Feedback;
import cn.stylefeng.guns.modular.service.impl.FeedbackServiceImpl;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-04-09
 */
@Controller
@RequestMapping("feedback")
public class FeedbackController extends BaseController {

    private static String PREFIX = "/feedback/";

    @Autowired
    private FeedbackServiceImpl feedbackService;

    /**
     * 意见反馈列表首页
     */
    @RequestMapping
    public ModelAndView index() {
        ModelAndView index = feedbackService.index();
        index.setViewName(PREFIX + "feedback.html");
        return index;
    }


    @ResponseBody
    @RequestMapping("list")
    public LayuiPageInfo list(String timeLimit, String keyword, Long type, Integer status) {
        //获取分页参数
        Page<Feedback> page = LayuiPageFactory.defaultPage();


        //拼接查询条件
        String beginTime = null;
        String endTime = null;

        if (ToolUtil.isNotEmpty(timeLimit)) {
            String[] split = timeLimit.split(" - ");
            beginTime = split[0];
            endTime = split[1];
        }
        //根据条件查询日志
        return feedbackService.getList(page, beginTime, endTime, keyword, type, status);
    }


    /**
     * 查看详情
     */
    @RequestMapping("details/{id}")
    public ModelAndView details(@PathVariable Long id) {
        ModelAndView details = feedbackService.details(id);
        details.setViewName(PREFIX + "feedback_details.html");
        return details;
    }

    /**
     * 处理反馈
     */
    @RequestMapping("handle")
    @ResponseBody
    public ResponseData handle(@RequestBody Feedback feedback) {
        feedbackService.handle(feedback);
        return SUCCESS_TIP;
    }

    /**
     * 删除反馈
     */
    @RequestMapping("delete/{id}")
    @ResponseBody
    public ResponseData delete(@PathVariable Long id) {
        feedbackService.delete(id);
        return SUCCESS_TIP;
    }

}

